/**
 * 1.
 */
let str = "wwws.jpg";

if (str.match('.gif')) {
    console.log("no gif");
} else {
    console.log("has gif");
}

/**
 * 2.
 */

//  function test2(obj) {
//      obj.url = "baidu.com";
//      obj = new Object();
//      obj.url = "google.com";
//      return obj;
//  }
// let o = new Object();
// o = test2(o);
// console.log(o.url);

/**
 * 3.
 */

var a = 1;
var obj = { b: 2 };
var fn = function() {}
fn.c = 3;

function test3(x, y, z) {
    x = 4;
    y.b = 5;
    z.c = 6;
    return z;
}
fn = test3(a, obj, fn);
console.log(a + obj.b + fn.c); //12 6+5+1


/**
 * 4.
 */
let arr1 = Array.apply(null, new Array(3));
let res1 = arr1.map(e => {
    e++;
})
console.log(res1); //[,,]
let arr2 = new Array(3);
let res2 = arr1.forEach(
    e => {
        e++;
    }
);
console.log(res2); //undefined

/**
 * 笔试1
 */
let nodes = [{ id: 2, name: "2", pId: 0 },
    { id: 4, name: "4", pId: 2 },
    { id: 12, name: "12", pId: 2 },
    { id: 8, name: "8", pId: 4 },
    { id: 10, name: "10", pId: 4 },
]

//转为 打印a
let a = {
    id: 2,
    name: "2",
    pId: 0,
    children: [{
            id: 4,
            name: "4",
            pId: 2,
            children: [
                { id: 8, name: "8", pId: 4 },
                { id: 10, name: "10", pId: 4 }
            ]
        },
        { id: 12, name: "12", pId: 2 },
    ]
}

/**
 * 笔试2 实现一个单例模式使用class
 */

class singleton {

    constructor(name) {
            this.name = name;
            this.instance = null;
        }
        //静态的 可以直接访问
    static getInstance() {
        if (this.instance) {
            return this.instance;
        }
        //保证只 new 一次
        return this.instance = new singleton();
    }


}